<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>修改标签</title>
    <%@ include file="../base/top.jsp" %>
</head>
<body class="no-skin" >
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <input type="text" name="labelId" id="label-id" style="display: none"/>
                        <input type="text" name="success" id="success" style="display: none"/>
                        <input type="text" name="msg" id="msg" style="display: none"/>
                        <div class="form-group">
                            <label>标签</label>
                            <input type="text" class="form-control" id="label-name" name="labelName" placeholder="标签名">
                        </div>
                        <div class="center">
                            <button id="save-btn" class="btn btn-mini btn-primary" onclick="save()">保存</button>
                            <button class="btn btn-mini btn-danger" onclick="top.Dialog.close()">取消</button>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<%@ include file="../base/foot.jsp" %>

<script>
    $(top.hangge());//关闭加载状态
    $(document).ready(function(){
        $("#label-id").val("${labelInfo.labelId}");
        if('${dotype}'=='edit'){
            $("#label-name").val("${labelInfo.labelName}");
        }
    });

    function save() {
        if(checkFormats()){
            var label ={};
            label.labelId = $("#label-id").val();
            label.labelName = $("#label-name").val();
            $.ajax({
                type:"POST",
                url:"<%=basePath%>label/${dotype}",
                data:label,
                dataType:'json',
                success:function (data) {
                    $("#success").val(data["success"]);
                    $("#msg").val(data["msg"]);
                    //关闭一定要写在ajax执行完成之后
                    top.Dialog.close();
                }
            });
        }
    }
    /**
     * 检查表单格式
     *
     * @create on 2018/11/27 by johnny
     * @update on 2018/12/27 by johnny
     */
    function checkFormats() {
        if($("#label-name").val()==null || $("#label-name").val()==""){
            top.operateError("标签名不能为空");
            $("#label-name").focus();
            return false;
        }
        var reg =/^[\u4E00-\u9FA5A-Za-z0-9_\^\%\&\'\,\;\=\?\$\+\-\\]{1,8}$/g;
        if(reg.test($("#label-name").val())){
            return true;
        }else{
            top.operateError("标签名1-8位且不能包含特殊字符");
            $("#label-name").focus();
            return false;
        }
        return false;
    }

</script>
</body>
</html>
